<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <h2 id="topic">querySelectorAll</h2>
    <p>段落1</p>
    <p class="blue">段落2</p>
    <div id="divContent">
      <p class="blue">段落3</p>
      <p class="topic blue">段落4</p>
      <p>段落5</p>
    </div>
    <script>
      //获取所有的p元素
      var ps = document.querySelectorAll('p')
      console.log(ps.length, ps)

      //获得id为divContent元素下的所有类为blue的p元素
      var divContent = document.querySelector('#divContent')
      var plue = divContent.querySelectorAll('p.blue')

      for (var i = 0, len = plue.length; i < len; i++) {
        plue[i].style.textDecoration = 'underline'
      }
    </script>
  </body>
</html>
